<script setup>
import Dialog from "@/components/dialog/Dialog.vue";
import dialogJson from "@/components/dialog/dialogJson.js";
import UserService from "@/service/impl/UserService.js";
import UserInfoModel from "@/model/UserInfoModel.js";

const t = inject('$t')
const info = dialogJson()
const user = ref(new UserInfoModel())

onMounted(() => {
    info.value.frame = true
    info.value.width = "50%"
    info.value.title = t('header.user.info')
    info.value.data = user.value
})

const show = () => {
    info.value.show = true
    info.value.load = true
    // 查当前用户
    UserService.info().then(res => {
        Object.assign(info.value.data, res.data)
        info.value.data.password = null
        info.value.load = false
    })
}

const updateInfo = () => {
    UserService.updateInfo(info.value.data)
}

defineExpose({show})
</script>

<template>
    <Dialog :dialog="info">
        <el-form :rules="info.data.rules" :model="info.data" style="width: 100%;padding: 5px">
            <el-form-item :label="$t('user.name')" prop="nickName">
                <el-input v-model="info.data.nickName" autocomplete="off"/>
            </el-form-item>
            <el-form-item :label="$t('user.email')" prop="email">
                <el-input v-model="info.data.email" autocomplete="off"/>
            </el-form-item>
            <el-form-item :label="$t('user.newPassword')" prop="newPassword">
                <el-input :placeholder="$t('user.pnp')" v-model="info.data.newPassword" autocomplete="off"/>
            </el-form-item>
            <el-form-item :label="$t('user.okPassword')" prop="okPassword">
                <el-input :placeholder="$t('user.pnp')" v-model="info.data.okPassword" autocomplete="off"/>
            </el-form-item>
        </el-form>
        <template #table-dialog-btn>
            <el-button @click="info.show = false">{{$t('btn.cancel')}}</el-button>
            <el-button type="primary" @click="updateInfo">{{$t('btn.confirm')}}</el-button>
        </template>
    </Dialog>
</template>

<style scoped lang="scss">

</style>